home *** CD-ROM | disk | FTP | other *** search
/ The Trig Explorer / The Trig Explorer.iso / mac / Explorer / plot.dxr / 00032.ls < prev    next >
Encoding:
Text File  |  2000-08-01  |  2.9 KB  |  87 lines

  1. on mouseDown me
  2.   set xCenter to the locH of sprite 3
  3.   set yCenter to the locV of sprite 3
  4.   set radius to the width of sprite 4 / 2
  5.   puppetSprite(the clickOn, 1)
  6.   puppetSprite(5, 1)
  7.   set the cursor of sprite the spriteNum of me to [member "Closed Hand", member "Closed Hand Mask"]
  8.   repeat while the stillDown
  9.     set mx to the mouseH
  10.     set my to the mouseV
  11.     set xAtMouse to mx - xCenter
  12.     set yAtMouse to my - yCenter
  13.     if xAtMouse <> 0 then
  14.       set angleAtMouse to atan(float(abs(yAtMouse)) / float(abs(xAtMouse)))
  15.       if angleAtMouse = 0 then
  16.         set yAtCircle to 0
  17.         set xAtCircle to radius * (xAtMouse / abs(xAtMouse))
  18.       else
  19.         set yAtCircle to sin(angleAtMouse) * float(radius) * (yAtMouse / abs(yAtMouse))
  20.         set xAtCircle to cos(angleAtMouse) * float(radius) * (xAtMouse / abs(xAtMouse))
  21.       end if
  22.     else
  23.       set xAtCircle to 0
  24.       if yAtMouse <> 0 then
  25.         set yAtCircle to radius * (yAtMouse / abs(yAtMouse))
  26.       else
  27.         set yAtCircle to radius
  28.       end if
  29.     end if
  30.     set the locH of sprite the clickOn to xCenter + xAtCircle
  31.     set the locV of sprite the clickOn to yCenter + yAtCircle
  32.     drawLine(5, yCenter, xCenter, the locV of sprite the clickOn, the locH of sprite the clickOn)
  33.     set dy to float(yCenter - the locV of sprite the clickOn)
  34.     set dy to -dy
  35.     set dx to float(xCenter - the locH of sprite the clickOn)
  36.     if dx = 0 then
  37.       if dy < 0 then
  38.         set theta1 to float(1.5 * PI)
  39.       else
  40.         set theta1 to float(PI / 2.0)
  41.       end if
  42.     else
  43.       if dx > 0 then
  44.         set theta1 to float(atan(float(dy / dx)))
  45.         if theta1 < 0 then
  46.           set theta1 to float(theta1) + (2.0 * PI)
  47.         end if
  48.       else
  49.         set theta1 to float(atan(float(dy / dx))) + PI
  50.       end if
  51.     end if
  52.     set the floatPrecision to 2
  53.     if theta1 > PI then
  54.       set theta1 to theta1 - PI
  55.     else
  56.       set theta1 to theta1 + PI
  57.     end if
  58.     set tempT to theta1 * 180.0 / PI
  59.     put float(1.0 * float(cos(theta1))) into field "X1"
  60.     put float(1.0 * float(sin(theta1))) into field "Y1"
  61.     put "(" & field "X1" & "," & field "Y1" & ")" into field "x-y"
  62.     set x0 to the locH of sprite 15
  63.     set y0 to the locV of sprite 15
  64.     puppetSprite(19, 1)
  65.     set the trails of sprite 19 to 1
  66.     set the locH of sprite 19 to (0.80000000000000004 * tempT) + x0
  67.     set the locV of sprite 19 to y0 - (50 * cos(theta1))
  68.     if the hilite of cast "Degrees" then
  69.       put theta1 * 180.0 / PI into field "theta"
  70.     else
  71.       put theta1 into field "theta"
  72.     end if
  73.     updateStage()
  74.   end repeat
  75.   set the cursor of sprite the spriteNum of me to [member "Hand", member "Hand Mask"]
  76. end
  77.  
  78. on beginSprite me
  79.   initializeCircle()
  80.   set the hilite of cast "Degrees" to 1
  81.   set the hilite of cast "Radians" to 0
  82.   set the castNum of sprite 16 to cast "Degs"
  83.   put "(1.00, 0.02)" into field "x-y"
  84.   put "0.02" into field "Y1"
  85.   put "1.00" into field "X1"
  86. end
  87.